<#macro templateList filepath=''>
    <@tools.fileList path=filepath>
        <#list list as a>
            <#if !a.directory><@t.merge 'paths' filepath?has_content?then(filepath+'/','')+a.fileName/></#if>
        </#list>
        <@sys.lock userId=admin.id itemType='template' itemIds=t.paths><#assign lockMap=map!/></@sys.lock>
        <#if lockMap?has_content>
            <#list lockMap as k,lock>
                <#if lock.userId?has_content><@t.merge 'userIds' lock.userId/></#if>
            </#list>
        </#if>
        <@sys.user ids=t.userIds><#assign userMap=map!/></@sys.user>
        <#list list as a>
            <#local path=filepath?has_content?then(filepath+'/','')+a.fileName>
            <li<#if a.directory> _src="cmsTemplate/list.html?parent=${path}"</#if>>
                <@tools.metadata path=path>
                    <a href="cmsTemplate/${a.directory?then('directory','content')}.html?path=${(path?url)!}" target="ajax" rel="cmsTemplateBox">
                        <#if !a.directory && lockMap?has_content && lockMap[path]?has_content>
                            <#assign lockUser=(userMap[lockMap[path].userId?string].nickname)!''/>
                            <i class="icon-lock icon-large" title="<@t.page 'lock.message' lockUser/> ${lockMap[path].createDate}"></i>
                        </#if>
                        ${(object.alias)?has_content?then(object.alias+' ('+a.fileName+')',a.fileName)}
                    </a>
                </@tools.metadata>
            </li>
        <#else>
            <li><a><@t.page 'empty_directory'/></a></li>
        </#list>
    </@tools.fileList>
</#macro>
<#if parent?has_content>
     <ul>
         <@templateList parent/>
     </ul>
<#else>
    <div class="pageContent">
        <div class="leftPageContent">
            <div class="card">
                <h2 class="contentTitle">
                    <a class="button" href="cmsTemplate/metadata.html" target="ajax" rel="cmsTemplateBox"><@t.page 'template.create'/></a>
                    <a class="button" href="cmsTemplate/demo.html" target="dialog" mask="true"><@t.page 'template.example'/></a></li>
                </h2>
                <ul class="tree treeFolder" layoutH>
                    <@templateList/>
                </ul>
            </div>
        </div>
        <div id="cmsTemplateBox" class="unitBox rightPageContent">
            <#if path?has_content>
                <#if editType?has_content&&'metadata'=editType>
                    <#include "metadata.html"/>
                <#else>
                    <#include "content.html"/>
                </#if>
            <#else>
                <#include "directory.html"/>
            </#if>
        </div>
    </div>
</#if>